from selenium import webdriver
from public.pages.basepage import BasePage
from data.input_elem import Tpshop_elems
from public.utils.read_ini import Read_ini
import os
from config.config import *
from selenium.webdriver.support.select import Select
from time import sleep
from ddt import ddt,data,unpack
from public.utils.get_excel_value import *
import json

file1=os.path.join(data_path,"data1.xls")
file=os.path.join(data_path,"data.ini")
r=Read_ini(file)
url=r.read_ini_data("tpshop_data","url")
username=r.read_ini_data("tpshop_data","login")
passwd=r.read_ini_data("tpshop_data","passwd")
verify=r.read_ini_data("tpshop_data","verify")
name=r.read_ini_data("tpshop_data","name")

@ddt
class  Tpshop(BasePage):
    def test001_login(self):
        self.driver = webdriver.Chrome()
        a=BasePage.set_driver(self.driver)
        BasePage.max()
        b=BasePage.get_driver()
        b.get(url)
        sleep(1)
        elem1=BasePage.search_elem(Tpshop_elems.login)
        BasePage.click(elem1)
        sleep(1)
        elem2=BasePage.search_elem(Tpshop_elems.username)
        BasePage.sendkeys(elem2,username)
        elem3=BasePage.search_elem(Tpshop_elems.passwd)
        BasePage.sendkeys(elem3,passwd)
        sleep(1)
        elem4=BasePage.search_elem(Tpshop_elems.verify)
        BasePage.sendkeys(elem4,verify)
        elem5=BasePage.search_elem(Tpshop_elems.loginbtn)
        BasePage.click(elem5)
        sleep(3)


    @data(*get_value(file_name=file1,sheet_name="Sheet1"))
    @unpack
    def test002_add_recv(self,province,values,town,place,address):
        sleep(2)
        ELEM1=BasePage.search_elem(Tpshop_elems.address_manage)
        BasePage.click(ELEM1)
        ELEM2=BasePage.search_elem(Tpshop_elems.add_new_address)
        BasePage.click(ELEM2)
        ELEM3=BasePage.search_elem(Tpshop_elems.iframe)
        BasePage.switch_frame(ELEM3)
        ELEM4=BasePage.search_elem(Tpshop_elems.name)
        BasePage.sendkeys(ELEM4,name)
        ELEM5=BasePage.search_elem(Tpshop_elems.province)
        Select(ELEM5).select_by_visible_text(province)
        sleep(2)
        ELEM6=BasePage.search_elem(Tpshop_elems.city)
        Select(ELEM6).select_by_value(values)
        sleep(2)
        ELEM7=BasePage.search_elem(Tpshop_elems.town)
        Select(ELEM7).select_by_visible_text(town)
        sleep(2)
        ELEM8=BasePage.search_elem(Tpshop_elems.place)
        Select(ELEM8).select_by_visible_text(place)
        sleep(2)
        ELEM9=BasePage.search_elem(Tpshop_elems.local)
        Select(ELEM9).select_by_visible_text(address)
        sleep(2)
        ELEM10=BasePage.search_elem(Tpshop_elems.savebtn)
        BasePage.click(ELEM10)

if __name__ == '__main__':
    import unittest
    unittest.main()
    # print(get_value(file_name=file1, sheet_name="add"))


    # elem1=BasePage.search_elem()
